package com.example.qxfw.mongodb.qx.service.impl;

import com.example.qxfw.common.entity.xt.ContourSetting;
import com.example.qxfw.common.mapper.MsgmediumsmallscaleMapperXml;
import com.example.qxfw.mongodb.qx.entity.QxGridFile;
import com.example.qxfw.mongodb.qx.service.QxGridFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class QxGridFileServiceImpl implements QxGridFileService {

    @Qualifier("mongoPrimaryTemplate")
    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private MsgmediumsmallscaleMapperXml msgmediumsmallscaleMapperXml;

    @Override
    public QxGridFile getById(String id) {
        return mongoTemplate.findById(id,QxGridFile.class);
    }

    @Override
    public QxGridFile save(QxGridFile qxGridFile) {
        return mongoTemplate.save(qxGridFile);
    }

    @Override
    public QxGridFile  queryListByDateCharTimeCharNtimesType(final String dateChar, final String timeChar, final String nTimes, final String type) {
        System.err.println(dateChar);
        System.err.println(timeChar);
        System.err.println(nTimes);
        System.err.println(type);

        Criteria criteria = Criteria
                .where("datechar").is(dateChar)
                .and("timechar").is(timeChar)
                .and("ntimes").is(nTimes)
                .and("type").is(type);

        Query query = new Query(criteria);

        return mongoTemplate.findOne(query, QxGridFile.class);
    }

    @Override
    public List<ContourSetting> getContourSetting(String paramtype) {
        return msgmediumsmallscaleMapperXml.getContourSetting(paramtype);
    }
}
